#ifndef IMGTEMPLATEMATCH_H
#define IMGTEMPLATEMATCH_H
#include "QString"
#include "QPoint"
#include "windows.h"
#include "win32util.h"
#include "tlbbcode.h"
#include "opencv2/core.hpp"
#include "opencv2/opencv.hpp"
#include "QScreen"
#include "QGuiApplication"
#include "QPixmap"
#include "QDebug"
#include "QSharedPointer"

#include "tesseract/baseapi.h"
#include "allheaders.h"
#include "QGlobalStatic"
#include "bean/stringboxbean.h"

using namespace tesseract;
using namespace cv;


class ImgHelper:public QObject
{
public:

    explicit ImgHelper(QObject *parent = nullptr);
    ~ImgHelper();
    static ImgHelper *getInstance();

    static QImage getGameWindowsScreenshots(QRectF rect = QRect());
    //单目标检测位置
    static bool getGameMatchPoint(QString templPath, QRectF *rect = nullptr);
    //单目标检测位置 (过时)
    Q_DECL_DEPRECATED static bool getGameMatchPoint(QString templPath, Scalar startScalar,Scalar endtScalar,  QRectF percentRect =  QRect(0, 0, 1, 1),QRectF *rect = nullptr);
    //单目标检测位置
    static bool getGameMatchPoint(QString templPath, Scalar startScalar, Scalar endtScalar, float threshold,QRectF percentRect = QRect(0, 0, 1, 1),  QRectF *outRect = nullptr);
    //绝对位置
    static bool getGameMatchPointAsb(QString templPath, Scalar startScalar, Scalar endtScalar,float threshold, QRectF rect, QRectF *outRect = nullptr);

    /**
     * @brief getGameMatchMultiPoint 多目标点检测位置
     * @param templPath
     * @param startScalar
     * @param endtScalar
     * @param threshold
     * @param listfloat
     * @param rect 百分比
     * @return
     */
    static bool getGameMatchMultiPoint(QString templPath,Scalar startScalar,Scalar endtScalar,float threshold, QList<QSharedPointer<QRectF>> *listfloat,QRectF percentRect = QRect(0, 0, 1, 1));

    static bool GetWindowBitmap();


    static Mat qImageToCvMat( const QImage &inImage, bool inCloneImageData = true );

    /**
     * @brief getRotatedRect
     * @param startScalar
     * @param endtScalar
     * @param threshold 颜色阈值
     * @param rect 绝对位置
     * @return
     */
    static QRect getRotatedRect(Scalar startScalar,Scalar endtScalar, QRect rect);

    static bool getTextByImg(Scalar startScalar, Scalar endtScalar, QRectF percentRect,StringBoxBean &strsInfo ,PageIteratorLevel level);

    static bool getNumByImg(Scalar startScalar, Scalar endtScalar, QRectF percentRect, StringBoxBean &strsInfo,PageIteratorLevel level);

    static bool getNumByImgAbs(Scalar startScalar, Scalar endtScalar, QRectF asbRect, StringBoxBean &strsInfo,PageIteratorLevel level);

private:
    static void getTextByMat(Mat mat, StringBoxBean &strsInfo ,PageIteratorLevel level);
    static void getNumByMat(Mat mat, StringBoxBean &strsInfo ,PageIteratorLevel level);
};

#endif // IMGTEMPLATEMATCH_H
